package cn.hist.hfp.converter;

import cn.hist.hfp.entity.CommodityProducer;
import cn.hist.hfp.vo.CommodityProducerVO;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class CommodityProducerConverter {

    public CommodityProducerVO converter(CommodityProducer commodityProducer) {
        return CommodityProducerVO.builder()
                .contactNumber(commodityProducer.getContactNumber())
                .id(commodityProducer.getId())
                .location(commodityProducer.getLocation())
                .name(commodityProducer.getName())
                .build();
    }

    public List<CommodityProducerVO> converter(List<CommodityProducer> commodityProducerList) {
        List<CommodityProducerVO> commodityProducerVOS = new ArrayList<>();
        for (CommodityProducer commodityProducer: commodityProducerList) {
            commodityProducerVOS.add(converter(commodityProducer));
        }
        return commodityProducerVOS;
    }

    public Set<CommodityProducerVO> converter(Set<CommodityProducer> commodityProducerSet) {
        Set<CommodityProducerVO> commodityProducerVOS = new HashSet<>();
        for (CommodityProducer commodityProducer: commodityProducerSet) {
            commodityProducerVOS.add(converter(commodityProducer));
        }
        return commodityProducerVOS;
    }

}
